using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Export.Xls;
using SM.core;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSGPP.func;
namespace TVSBH.func
{
	public class frmBookInput : Form
	{
		private IContainer components = null;
		private DataGridView dgvProduct;
		private Button btnClose;
		private System.Windows.Forms.Label label1;
		private Button btnPrint;
		private Button btnExportToExcel;
		private DataGridViewTextBoxColumn createDate;
		private DataGridViewTextBoxColumn productName;
		private DataGridViewTextBoxColumn billID;
		private DataGridViewTextBoxColumn Packet;
		private DataGridViewTextBoxColumn ProductExpiryDate;
		private DataGridViewTextBoxColumn Provider;
		private DataGridViewTextBoxColumn productUnit;
		private DataGridViewTextBoxColumn productNumber;
		private DataGridViewTextBoxColumn productPrice;
		private DataGridViewTextBoxColumn ProductMoney;
		private DataGridViewTextBoxColumn Column3;
		private Func objFunc = new Func();
		private DataTable objTable = new DataTable();
		private Bill objBill = new Bill();
		public string userName = "";
		public string fullName = "";
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle6 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle7 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle8 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle9 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle10 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle11 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmBookInput));
			this.dgvProduct = new DataGridView();
			this.createDate = new DataGridViewTextBoxColumn();
			this.productName = new DataGridViewTextBoxColumn();
			this.billID = new DataGridViewTextBoxColumn();
			this.Packet = new DataGridViewTextBoxColumn();
			this.ProductExpiryDate = new DataGridViewTextBoxColumn();
			this.Provider = new DataGridViewTextBoxColumn();
			this.productUnit = new DataGridViewTextBoxColumn();
			this.productNumber = new DataGridViewTextBoxColumn();
			this.productPrice = new DataGridViewTextBoxColumn();
			this.ProductMoney = new DataGridViewTextBoxColumn();
			this.Column3 = new DataGridViewTextBoxColumn();
			this.btnClose = new Button();
			this.label1 = new System.Windows.Forms.Label();
			this.btnPrint = new Button();
			this.btnExportToExcel = new Button();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			base.SuspendLayout();
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToOrderColumns = true;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeight = 26;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.createDate,
				this.productName,
				this.billID,
				this.Packet,
				this.ProductExpiryDate,
				this.Provider,
				this.productUnit,
				this.productNumber,
				this.productPrice,
				this.ProductMoney,
				this.Column3
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new System.Drawing.Point(7, 39);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvProduct.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(886, 521);
			this.dgvProduct.TabIndex = 1;
			this.createDate.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.createDate.DataPropertyName = "createDate";
			dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle2.Format = "D";
			dataGridViewCellStyle2.NullValue = null;
			this.createDate.DefaultCellStyle = dataGridViewCellStyle2;
			this.createDate.Frozen = true;
			this.createDate.HeaderText = "Ngày";
			this.createDate.MinimumWidth = 80;
			this.createDate.Name = "createDate";
			this.createDate.ReadOnly = true;
			this.createDate.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.createDate.Width = 80;
			this.productName.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productName.DataPropertyName = "productName";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft;
			this.productName.DefaultCellStyle = dataGridViewCellStyle3;
			this.productName.Frozen = true;
			this.productName.HeaderText = "Tên thuốc, Hàm lượng, Quy cách";
			this.productName.MinimumWidth = 200;
			this.productName.Name = "productName";
			this.productName.ReadOnly = true;
			this.productName.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productName.Width = 200;
			this.billID.DataPropertyName = "billID";
			dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle4.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle4.ForeColor = Color.Black;
			this.billID.DefaultCellStyle = dataGridViewCellStyle4;
			this.billID.Frozen = true;
			this.billID.HeaderText = "Số hoá đơn";
			this.billID.MinimumWidth = 120;
			this.billID.Name = "billID";
			this.billID.ReadOnly = true;
			this.billID.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.billID.Width = 120;
			this.Packet.DataPropertyName = "Packet";
			dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle5.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle5.ForeColor = Color.Black;
			dataGridViewCellStyle5.Format = "N0";
			dataGridViewCellStyle5.NullValue = null;
			this.Packet.DefaultCellStyle = dataGridViewCellStyle5;
			this.Packet.Frozen = true;
			this.Packet.HeaderText = "Số lô";
			this.Packet.MinimumWidth = 80;
			this.Packet.Name = "Packet";
			this.Packet.ReadOnly = true;
			this.Packet.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Packet.Width = 80;
			this.ProductExpiryDate.DataPropertyName = "ProductExpiryDate";
			dataGridViewCellStyle6.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle6.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle6.ForeColor = Color.Black;
			dataGridViewCellStyle6.Format = "D";
			dataGridViewCellStyle6.NullValue = null;
			this.ProductExpiryDate.DefaultCellStyle = dataGridViewCellStyle6;
			this.ProductExpiryDate.Frozen = true;
			this.ProductExpiryDate.HeaderText = "Hạn dùng";
			this.ProductExpiryDate.MinimumWidth = 80;
			this.ProductExpiryDate.Name = "ProductExpiryDate";
			this.ProductExpiryDate.ReadOnly = true;
			this.ProductExpiryDate.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.ProductExpiryDate.Width = 80;
			this.Provider.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Provider.DataPropertyName = "ProviderName";
			dataGridViewCellStyle7.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle7.Font = new Font("Arial", 9.75f, FontStyle.Bold, GraphicsUnit.Point, 0);
			dataGridViewCellStyle7.ForeColor = Color.Black;
			this.Provider.DefaultCellStyle = dataGridViewCellStyle7;
			this.Provider.HeaderText = "Nhà cung cấp";
			this.Provider.MinimumWidth = 350;
			this.Provider.Name = "Provider";
			this.Provider.ReadOnly = true;
			this.Provider.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Provider.Width = 350;
			this.productUnit.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productUnit.DataPropertyName = "productUnit";
			dataGridViewCellStyle8.Alignment = DataGridViewContentAlignment.MiddleLeft;
			this.productUnit.DefaultCellStyle = dataGridViewCellStyle8;
			this.productUnit.HeaderText = "Đơn vị tính";
			this.productUnit.MinimumWidth = 80;
			this.productUnit.Name = "productUnit";
			this.productUnit.ReadOnly = true;
			this.productUnit.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productUnit.Width = 80;
			this.productNumber.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productNumber.DataPropertyName = "productNumber";
			dataGridViewCellStyle9.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle9.Format = "N0";
			dataGridViewCellStyle9.NullValue = "0";
			this.productNumber.DefaultCellStyle = dataGridViewCellStyle9;
			this.productNumber.HeaderText = "Số lượng";
			this.productNumber.MinimumWidth = 65;
			this.productNumber.Name = "productNumber";
			this.productNumber.ReadOnly = true;
			this.productNumber.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.productNumber.Width = 65;
			this.productPrice.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.productPrice.DataPropertyName = "productPrice";
			dataGridViewCellStyle10.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle10.Format = "N0";
			dataGridViewCellStyle10.NullValue = "0";
			this.productPrice.DefaultCellStyle = dataGridViewCellStyle10;
			this.productPrice.HeaderText = "Đơn giá";
			this.productPrice.MinimumWidth = 100;
			this.productPrice.Name = "productPrice";
			this.productPrice.ReadOnly = true;
			this.productPrice.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.ProductMoney.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ProductMoney.DataPropertyName = "ProductMoney";
			dataGridViewCellStyle11.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle11.Format = "N0";
			dataGridViewCellStyle11.NullValue = "0";
			this.ProductMoney.DefaultCellStyle = dataGridViewCellStyle11;
			this.ProductMoney.HeaderText = "Thành tiền";
			this.ProductMoney.MinimumWidth = 120;
			this.ProductMoney.Name = "ProductMoney";
			this.ProductMoney.ReadOnly = true;
			this.ProductMoney.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.ProductMoney.Width = 120;
			this.Column3.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column3.HeaderText = "Ghi chú";
			this.Column3.MinimumWidth = 70;
			this.Column3.Name = "Column3";
			this.Column3.ReadOnly = true;
			this.Column3.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new System.Drawing.Point(787, 566);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(106, 26);
			this.btnClose.TabIndex = 38;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.label1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.label1.BackColor = SystemColors.ControlLight;
			this.label1.Font = new Font("Arial", 12f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.label1.Location = new System.Drawing.Point(7, 13);
			this.label1.Name = "label1";
			this.label1.Size = new Size(886, 26);
			this.label1.TabIndex = 58;
			this.label1.Text = "SỔ NHẬP THUỐC";
			this.label1.TextAlign = ContentAlignment.MiddleCenter;
			this.btnPrint.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnPrint.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnPrint.FlatStyle = FlatStyle.Flat;
			this.btnPrint.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnPrint.Location = new System.Drawing.Point(7, 565);
			this.btnPrint.Name = "btnPrint";
			this.btnPrint.Size = new Size(111, 26);
			this.btnPrint.TabIndex = 66;
			this.btnPrint.Text = "In báo cáo [ F7 ]";
			this.btnPrint.UseVisualStyleBackColor = true;
			this.btnPrint.Click += new EventHandler(this.btnUpdate_Click);
			this.btnExportToExcel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnExportToExcel.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnExportToExcel.FlatStyle = FlatStyle.Flat;
			this.btnExportToExcel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnExportToExcel.Location = new System.Drawing.Point(121, 565);
			this.btnExportToExcel.Name = "btnExportToExcel";
			this.btnExportToExcel.Size = new Size(104, 26);
			this.btnExportToExcel.TabIndex = 67;
			this.btnExportToExcel.Text = "Xuất File Excel";
			this.btnExportToExcel.UseVisualStyleBackColor = true;
			this.btnExportToExcel.Click += new EventHandler(this.btnExportToExcel_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.btnExportToExcel);
			base.Controls.Add(this.btnPrint);
			base.Controls.Add(this.label1);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.dgvProduct);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.Name = "frmBookInput";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "SỐ NHẬP THUỐC";
			base.WindowState = FormWindowState.Maximized;
			base.Load += new EventHandler(this.frmInput_Load);
			base.KeyDown += new KeyEventHandler(this.frmInput_KeyDown);
			((ISupportInitialize)this.dgvProduct).EndInit();
			base.ResumeLayout(false);
		}
		public frmBookInput()
		{
			this.InitializeComponent();
		}
		private void frmInput_Load(object sender, EventArgs e)
		{
			this.dgvProduct.AutoGenerateColumns = false;
			this.getInfomation();
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmInput_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.F7)
			{
				this.btnPrint.PerformClick();
			}
			else
			{
				if (e.KeyCode == Keys.Escape)
				{
					base.Close();
				}
			}
		}
		public void getInfomation()
		{
			try
			{
				DataColumn column = new DataColumn("billID", typeof(string));
				DataColumn column2 = new DataColumn("createDate", typeof(DateTime));
				DataColumn column3 = new DataColumn("productName", typeof(string));
				DataColumn column4 = new DataColumn("Packet", typeof(string));
				DataColumn column5 = new DataColumn("ProductExpiryDate", typeof(DateTime));
				DataColumn column6 = new DataColumn("productNumber", typeof(float));
				DataColumn column7 = new DataColumn("productUnit", typeof(string));
				DataColumn column8 = new DataColumn("productPrice", typeof(float));
				DataColumn column9 = new DataColumn("ProductMoney", typeof(float));
				DataColumn column10 = new DataColumn("ProviderName", typeof(string));
				this.objTable.Columns.Add(column);
				this.objTable.Columns.Add(column2);
				this.objTable.Columns.Add(column3);
				this.objTable.Columns.Add(column4);
				this.objTable.Columns.Add(column5);
				this.objTable.Columns.Add(column6);
				this.objTable.Columns.Add(column7);
				this.objTable.Columns.Add(column8);
				this.objTable.Columns.Add(column9);
				this.objTable.Columns.Add(column10);
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = sqlConnection.CreateCommand();
				sqlCommand.CommandText = "SELECT *, dbo.uf_getProviderName(TabBill.PID) AS ProviderName FROM [TabDetailBill],[TabBill] WHERE TypeInput IN ('IN1','IN2','IN3') AND [TabDetailBill].[billID] = [TabBill].[ID] ORDER BY [TabBill].[createDate] ASC";
				SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
				while (sqlDataReader.Read())
				{
					if (!this.checkInDataGridView(sqlDataReader["billID"].ToString()))
					{
						this.objTable.Rows.Add(new object[]
						{
							sqlDataReader["billID"].ToString(),
							sqlDataReader["createDate"].ToString(),
							sqlDataReader["productName"].ToString(),
							sqlDataReader["Packet"].ToString(),
							sqlDataReader["ProductExpiryDate"].ToString(),
							sqlDataReader["productNumber"].ToString(),
							sqlDataReader["productUnit"].ToString(),
							sqlDataReader["productPrice"].ToString(),
							sqlDataReader["ProductMoney"].ToString(),
							sqlDataReader["ProviderName"].ToString()
						});
					}
					else
					{
						this.objTable.Rows.Add(new object[]
						{
							sqlDataReader["billID"].ToString(),
							null,
							sqlDataReader["productName"].ToString(),
							sqlDataReader["Packet"].ToString(),
							sqlDataReader["ProductExpiryDate"].ToString(),
							sqlDataReader["productNumber"].ToString(),
							sqlDataReader["productUnit"].ToString(),
							sqlDataReader["productPrice"].ToString(),
							sqlDataReader["ProductMoney"].ToString(),
							sqlDataReader["ProviderName"].ToString()
						});
					}
				}
				sqlDataReader.Close();
				sqlConnection.Close();
				sqlConnection.Dispose();
				this.dgvProduct.DataSource = this.objTable;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				this.objTable = null;
				this.dgvProduct.DataSource = this.objTable;
			}
		}
		private void btnSearch_Click(object sender, EventArgs e)
		{
			this.getInfomation();
		}
		private void resetDataGridView()
		{
			this.objTable = null;
			this.dgvProduct.DataSource = this.objTable;
		}
		private void btnEdit_Click(object sender, EventArgs e)
		{
			new frmAddSideEffects
			{
				ID = "0"
			}.ShowDialog();
		}
		private void btnUpdate_Click(object sender, EventArgs e)
		{
			frmBookSellNotBillView frmBookSellNotBillView = new frmBookSellNotBillView();
			frmBookSellNotBillView.objectName = "BookInput";
			frmBookInputPrint.objTable = this.objTable;
			frmBookSellNotBillView.ShowDialog();
		}
		private void btnExportToExcel_Click(object sender, EventArgs e)
		{
			try
			{
				frmBookInputPrint.objTable = new DataTable();
				frmBookInputPrint.objTable = this.objTable;
				ActiveReport3 activeReport = new frmBookInputPrint();
				activeReport.Run();
				XlsExport xlsExport = new XlsExport();
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.ShowDialog();
				string text = saveFileDialog.FileName;
				if (text != "")
				{
					if (!text.ToUpper().Contains(".XLS"))
					{
						text += ".xls";
					}
					xlsExport.MinRowHeight = 0f;
					xlsExport.UseCellMerging = true;
					xlsExport.Export(activeReport.Document, text);
					MessageBox.Show("Hệ thống đã hoàn thành việc xuất dữ liệu ra file Excel", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					MessageBox.Show("Bạn chưa chọn đường dẫn và tên file cần xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch
			{
			}
		}
		private bool checkInDataGridView(string billID)
		{
			bool result = false;
			for (int i = 0; i < this.objTable.Rows.Count; i++)
			{
				if (this.objTable.Rows[i]["billID"].ToString().ToUpper() == billID)
				{
					result = true;
				}
			}
			return result;
		}
	}
}
